﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string input = textBox1.Text.Trim();
            if (string.IsNullOrEmpty(input) || input.Length > 1)
            {
                MessageBox.Show("请输入一个字符（仅限字母、数字 1 - 9）");
                return;
            }

            char ch = input[0];
         
            if (!((ch >= '1' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')))
            {
                MessageBox.Show("输入字符不符合要求，请输入数字 1 - 9、大写或小写字母");
                return;
            }

            string triangle = "";
            int count = 1;
        
            int maxCount;
            if (ch >= '1' && ch <= '9')
            {
                maxCount = ch - '0';
            }
            else
            {
                maxCount = 'Z' - (ch >= 'a' && ch <= 'z' ? 'a' : 'A') + 1;
            }

            for (int i = 0; i < maxCount; i++)
            {
                char currentChar;
                if (ch >= '1' && ch <= '9')
                {
                    currentChar = ch;
                }
                else
                {
                    currentChar = (char)(ch + i);
                  
                    if (ch >= 'a' && ch <= 'z' && currentChar > 'z')
                    {
                        break;
                    }
                    if (ch >= 'A' && ch <= 'Z' && currentChar > 'Z')
                    {
                        break;
                    }
                }

             
                for (int j = 0; j < maxCount - i - 1; j++)
                {
                    triangle += " ";
                }

             
                for (int j = 0; j < 2 * count - 1; j++)
                {
                    triangle += currentChar;
                }

                triangle += Environment.NewLine;
                count++;
            }

            label2.Text = triangle;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            label2.Text = "";
        }
    }
}